import { fetchProducts } from '../../services/api';

Page({
  data: {
    featuredProducts: [],
  },

  onLoad() {
    this.loadFeaturedProducts();
  },

  onShow() {
    this.getTabBar().init();
  },

  // 加载推荐商品
  loadFeaturedProducts() {
    fetchProducts().then(res => {
      // 简单地取前5个商品作为推荐
      const featured = res.products.slice(0, 5);
      this.setData({ featuredProducts: featured });
    });
  },

  // 跳转到点餐菜单页
  goToMenu() {
    wx.switchTab({
      url: '/pages/menu/index',
    });
  },

  onShareAppMessage() {
    return {
      title: '欢迎光临Gemini KTV',
      path: '/pages/home/home',
    };
  },
});